/**
 * @author daniele.gili@usi.ch
 */

package ch.usi.inf.pf2;

import java.awt.Graphics;
import java.util.ArrayList;
import java.util.Timer;

public class Input extends Pin implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Wire inputValue = null;
	private CommonGate theGate = null;

	public Input(int x, int y, CommonGate gate) {

		theGate = gate;
		this.x = x - theGate.getWidth() / 2 - width;
		this.y = y;
	}

	public Input(CommonGate gate) {
		theGate = gate;
		this.x = 0;
		this.y = 0;
	}

	public void setInput(Wire wi) {
		inputValue = wi;
	}

	public Wire getInput() {
		return inputValue;
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public void setNewAttributes(final int x, final int y, int c, int g) {
		if (c == 1 && !(theGate instanceof MegaOutput)) {
			this.x = this.x + x;
			this.y = this.y + y;
			
		} else if (c > 1) {

			if (g == 0) {
				this.x = this.x + x;
				this.y = this.y + y;
			}

			if (g == 1) {
				this.x = this.x + x;
				this.y = this.y + y;
			}

		}

		else if (theGate instanceof MegaOutput) {
			this.x = this.x + x;
			this.y = this.y + y;
		}
	}
	

	public Integer getValue(int index) {
		try {
			actualValue = inputValue.getValue(index);
			return actualValue;
		} catch (Exception e) {
			return null;
		}

	}




	public void draw(final Graphics g) {
		g.drawRect(x, y, width, height);
	}
}
